package com.cash.loan.modular.cash.util;


import com.cash.loan.modular.cash.result.PageResult;
import com.github.pagehelper.Page;

import java.util.List;

/**
 * Created by Administrator on 2017/8/8.
 */
public class PageBeanUtil {

    public static <T> PageResult<T> toPageResult(List<T> datas) {
        PageResult<T> result = new PageResult<T>();
        if (datas instanceof Page) {
            Page page = (Page) datas;
            result.setPageNo(page.getPageNum());
            result.setDataList(page.getResult());
            result.setPageSize(page.getPageSize());
            result.setTotal(page.getTotal());
            result.setPages(page.getPages());
        } else {
            result.setPageNo(1);
            result.setPageSize(datas.size());
            result.setDataList(datas);
            result.setTotal(datas.size());
        }
        return result;
    }
}
